package com.ruoyi.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.manage.domain.SalSalaryDeduct;
import com.ruoyi.manage.service.ISalSalaryDeductService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 薪资扣款项配置Controller
 * 
 * @author cf
 * @date 2025-06-04
 */
@RestController
@RequestMapping("/manage/deduct")
public class SalSalaryDeductController extends BaseController
{
    @Autowired
    private ISalSalaryDeductService salSalaryDeductService;

    /**
     * 查询薪资扣款项配置列表
     */
    @PreAuthorize("@ss.hasPermi('manage:deduct:list')")
    @GetMapping("/list")
    public TableDataInfo list(SalSalaryDeduct salSalaryDeduct)
    {
        startPage();
        List<SalSalaryDeduct> list = salSalaryDeductService.selectSalSalaryDeductList(salSalaryDeduct);
        return getDataTable(list);
    }

    /**
     * 导出薪资扣款项配置列表
     */
    @PreAuthorize("@ss.hasPermi('manage:deduct:export')")
    @Log(title = "薪资扣款项配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SalSalaryDeduct salSalaryDeduct)
    {
        List<SalSalaryDeduct> list = salSalaryDeductService.selectSalSalaryDeductList(salSalaryDeduct);
        ExcelUtil<SalSalaryDeduct> util = new ExcelUtil<SalSalaryDeduct>(SalSalaryDeduct.class);
        util.exportExcel(response, list, "薪资扣款项配置数据");
    }

    /**
     * 获取薪资扣款项配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:deduct:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(salSalaryDeductService.selectSalSalaryDeductById(id));
    }

    /**
     * 新增薪资扣款项配置
     */
    @PreAuthorize("@ss.hasPermi('manage:deduct:add')")
    @Log(title = "薪资扣款项配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SalSalaryDeduct salSalaryDeduct)
    {
        return toAjax(salSalaryDeductService.insertSalSalaryDeduct(salSalaryDeduct));
    }

    /**
     * 修改薪资扣款项配置
     */
    @PreAuthorize("@ss.hasPermi('manage:deduct:edit')")
    @Log(title = "薪资扣款项配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SalSalaryDeduct salSalaryDeduct)
    {
        return toAjax(salSalaryDeductService.updateSalSalaryDeduct(salSalaryDeduct));
    }

    /**
     * 删除薪资扣款项配置
     */
    @PreAuthorize("@ss.hasPermi('manage:deduct:remove')")
    @Log(title = "薪资扣款项配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(salSalaryDeductService.deleteSalSalaryDeductByIds(ids));
    }
}
